package ${package.Controller};


import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.yoahh.annotation.AutoLog;
import ${cfg.queryUrl}.${entity}QueryInfo;

import top.yoahh.common.Result;
import ${package.Entity}.${entity};
import java.util.List;

<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>
import ${package.Service}.${entity}Service;
/**
 * <p>
 * ${table.comment!} 前端控制器
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@Api(tags = "${table.comment!}")
@RequestMapping("/${table.entityPath}")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>
    @Autowired
    private ${entity}Service ${table.entityPath}Service;

    @AutoLog(value = "${table.comment!}-新增")
    @ApiOperation(value = "新增")
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public Result add(@RequestBody ${entity} ${table.entityPath}){
        ${table.entityPath}Service.save(${table.entityPath});
        return Result.ok();
    }

    @AutoLog(value = "${table.comment!}-分页查询")
    @ApiOperation(value = "分页查询")
    @RequestMapping(value = "/queryPage",method = RequestMethod.POST)
    public PageInfo<${entity}> queryPage(@RequestBody ${entity}QueryInfo queryInfo){
        return ${table.entityPath}Service.queryPage(queryInfo);
    }

    @AutoLog(value = "${table.comment!}-批量删除")
    @ApiOperation(value = "批量删除")
    @RequestMapping(value = "/deleteBatch",method = RequestMethod.DELETE)
    public Result deleteBatch(@RequestBody List<String> ids){
        return ${table.entityPath}Service.deleteBatch(ids);
    }

    @AutoLog(value = "${table.comment!}-按照ID删除")
    @ApiOperation(value = "按照ID删除")
    @RequestMapping(value = "/delete/{id}",method = RequestMethod.GET)
    public Result delete(@PathVariable("id") String id){
        return ${table.entityPath}Service.delete(id);
    }

    @AutoLog(value = "${table.comment!}-修改")
    @ApiOperation(value = "修改")
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    public Result update(@RequestBody ${entity} ${table.entityPath}){
        ${table.entityPath}Service.updateById( ${table.entityPath});
        return Result.ok();
    }
}
</#if>
